﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JoseDiego_Data_Mudanca_Requisito_01
{
	class DateUtil
	{
		#region Variaveis e Construtor
		private List<DateTime> listHoliday;
		private List<DateTime> listDayUtil;

		public DateUtil()
		{
			loadHoliday();
		}
		#endregion

		public List<DateTime> ReturnDaysUtils( DateTime dateSpecific, int amountDays )
		{		
			listDayUtil = new List<DateTime>();

			DateTime subtractDate = dateSpecific;

			for( int i = 1; listDayUtil.Count < amountDays; i++ )
			{
				subtractDate = subtractDate.AddDays( -1 );

				if( !checkHoliday( subtractDate ) && subtractDate.DayOfWeek != DayOfWeek.Sunday && subtractDate.DayOfWeek != DayOfWeek.Saturday )
				{
					listDayUtil.Add( subtractDate );
				}
			}

			return listDayUtil;
		}

		public List<DateTime> ReturnDaysCalendar( int amountDays )
		{
			List<DateTime> listDaysCalendar = new List<DateTime>();

			DateTime subtractDate = DateTime.Now;

			for( int i = 1; listDaysCalendar.Count < amountDays; i++ )
			{
				subtractDate = subtractDate.AddDays( -1 );

				listDaysCalendar.Add( subtractDate );
			}

			return listDaysCalendar;
		}

		private bool checkHoliday( DateTime date )
		{
			bool valueReturn = false;

			foreach( DateTime dateHol in listHoliday )
			{
				if( dateHol == date )
				{
					valueReturn = true;
					break;
				}
			}

			return valueReturn;
		}

		private void loadHoliday()
		{
			listHoliday = new List<DateTime>();

			listHoliday.Add( new DateTime(2012, 01, 01));
			listHoliday.Add( new DateTime(2012, 02, 21));
			listHoliday.Add( new DateTime(2012, 12, 25));
			listHoliday.Add( new DateTime(2012, 12, 31));
		}
	}
}
